import random
# 字典
d={10:"cat",20:"dog"}
print(d)

lst1=[10,20,30,40]
lst2=['a','b','c','d','e']
zipobj=zip(lst1,lst2)
# print(zipobj)
# print(list(zipobj))
d=dict(zipobj)
print(d)

d2=dict(cat=10,dog=20)
print(d2)

# 字典的遍历
d3={"hello":10, "world":20, "python":30}

print(d3["hello"]) # 键不存在时报错
print(d3.get("hello")) # 键不存在时，返回None, 可使用d3.get('hello',默认值)

for i in d.items():
    print(i)

for key,value in d.items():
    print(key,value)

print(list(d3.keys()))
print(tuple(d3.keys()))
print(d3.values())

lst = list(d3.items())
print(lst)

d4=dict(lst)
print(d4)

# 字典生成式
# d = { key:value for item in range}
d5={item:random.randint(1,100) for item in range(4)}
print(d5)
# d = { key:value for key,value in zip(lst1,lst2)}


d6={'a':10,'b':20}
d7={'c':30, 'd':40}
merged_dict=d6|d7
print(merged_dict)


lst=[]
for i in '想念':
    for j in '家人':
        lst.append(i + j)
print(lst)

lst=[1,3,5,7,9]
print(lst.reverse())
print(lst)
